package com.RMP
{
    import flash.display.*;
    import flash.events.*;

    public class PartnerShell extends Sprite
    {
        var startIndexChar:String;
        var myXMLList:XMLList;
        var counter:int;
        var fadeSpeed:Number;
        var iconsArray:Array;
        var partnerImage:PartnerImage;
        var myRoot:MovieClip;
        var startIndexNum:int;

        public function PartnerShell(param1:MovieClip, param2:Number, param3:XMLList, param4) : void
        {
            myRoot = param1;
            fadeSpeed = param2;
            myXMLList = param3;
            startIndexNum = param4;
            buildList();
            myRoot.stage.addEventListener(Event.RESIZE, onResizer);
            doResize();
            return;
        }

        function doResize() : void
        {
            var _loc_1:int = 0;
            _loc_1 = 0;
            while (_loc_1 < counter)
            {
                
                iconsArray[_loc_1].x = Math.round(_loc_1 % 4 * 3 * (myRoot.unitW + myRoot.gutterW));
                iconsArray[_loc_1].y = Math.round(Math.floor(_loc_1 / 4) * 2 * (myRoot.unitH + myRoot.gutterH));
                _loc_1++;
            }
            return;
        }

        function buildList() : void
        {
            var _loc_1:* = undefined;
            var _loc_2:int = 0;
            var _loc_3:String = null;
            var _loc_4:String = null;
            _loc_1 = (startIndexNum - 1) * 8;
            counter = 0;
            iconsArray = new Array();
            _loc_2 = _loc_1;
            while (_loc_2 < myXMLList.item.length())
            {
                
                switch(myRoot.pathNames[1])
                {
                    case "partners":
                    {
                        _loc_3 = "p";
                        break;
                    }
                    case "staff":
                    {
                        switch(myRoot.pathNames[3])
                        {
                            case "senior-staff":
                            {
                                _loc_3 = "p";
                                break;
                            }
                            case "associates":
                            {
                                _loc_3 = "a";
                                break;
                            }
                            default:
                            {
                                break;
                            }
                        }
                        break;
                    }
                    default:
                    {
                        break;
                    }
                }
                _loc_4 = myXMLList.item[_loc_2].@label;
                partnerImage = new PartnerImage(myRoot, fadeSpeed, _loc_4, counter, myXMLList.item[_loc_2].@id, myXMLList.item[_loc_2].thumbnail.@icon, _loc_3, myXMLList.item[_loc_2].thumbnail.@iBorder);
                addChild(partnerImage);
                if (myRoot.pathNames[3] == "associates")
                {
                    partnerImage.buttonMode = false;
                    partnerImage.mouseChildren = false;
                }
                else
                {
                    partnerImage.buttonMode = true;
                    partnerImage.mouseChildren = false;
                }
                partnerImage.addEventListener(MouseEvent.MOUSE_OVER, btnRollOver);
                partnerImage.addEventListener(MouseEvent.MOUSE_OUT, btnRollOut);
                partnerImage.addEventListener(MouseEvent.CLICK, btnClick);
                iconsArray.push(partnerImage);
                var _loc_6:* = counter + 1;
                counter = _loc_6;
                if (counter == 8)
                {
                    break;
                }
                _loc_2++;
            }
            return;
        }

        function onResizer(event:Event)
        {
            doResize();
            return;
        }

        function btnRollOver(event:MouseEvent)
        {
            if (myRoot.pathNames[3] != "associates")
            {
                event.currentTarget.rollOverEvent();
            }
            return;
        }

        function btnRollOut(event:MouseEvent)
        {
            if (myRoot.pathNames[3] != "associates")
            {
                event.currentTarget.rollOutEvent();
            }
            return;
        }

        function btnClick(event:MouseEvent) : void
        {
            if (myRoot.pathNames[3] != "associates")
            {
                updateAddress(event.currentTarget.projectId);
                event.currentTarget.buttonMode = false;
                event.currentTarget.removeEventListener(MouseEvent.CLICK, btnClick);
                event.currentTarget.removeEventListener(MouseEvent.MOUSE_OVER, btnRollOver);
                event.currentTarget.removeEventListener(MouseEvent.MOUSE_OUT, btnRollOut);
            }
            return;
        }

        function updateAddress(param1) : void
        {
            switch(myRoot.pathNames[1])
            {
                case "partners":
                {
                    myRoot.clickPathNames = ["practice", "partners", myRoot.pathNames[2], param1, 0];
                    myRoot.updateAddress("/" + "practice" + "/" + "partners" + "/" + myRoot.pathNames[2] + "/" + param1 + "/" + 0 + "/");
                    break;
                }
                case "staff":
                {
                    switch(myRoot.pathNames[2])
                    {
                        case "new-york":
                        {
                            if (myRoot.pathNames[3] == "senior-staff")
                            {
                                myRoot.clickPathNames = ["practice", "staff", "new-york", "senior-staff", myRoot.pathNames[4], param1, 0];
                                myRoot.updateAddress("/" + "practice" + "/" + "staff" + "/" + "new-york" + "/" + "senior-staff" + "/" + myRoot.pathNames[4] + "/" + param1 + "/" + 0 + "/");
                            }
                            break;
                        }
                        case "los-angeles":
                        {
                            if (myRoot.pathNames[3] == "senior-staff")
                            {
                                myRoot.clickPathNames = ["practice", "staff", "los-angeles", "senior-staff", myRoot.pathNames[4], param1, 0];
                                myRoot.updateAddress("/" + "practice" + "/" + "staff" + "/" + "los-angeles" + "/" + "senior-staff" + "/" + myRoot.pathNames[4] + "/" + param1 + "/" + 0 + "/");
                            }
                            break;
                        }
                        default:
                        {
                            break;
                        }
                    }
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }

    }
}
